

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="zh" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="zh" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Integration &mdash; Optuna 1.4.0 文档</title>
  

  
  
    <link rel="shortcut icon" href="../_static/favicon.ico"/>
  
  
  

  
  <script type="text/javascript" src="../_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/custom.css" type="text/css" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="next" title="Logging" href="logging.html" />
    <link rel="prev" title="Hyperparameter Importance" href="importance.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../index.html" class="icon icon-home"> Optuna
          

          
          </a>

          
            
            
              <div class="version">
                1.4.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">目录</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../installation.html">安装</a></li>
<li class="toctree-l1"><a class="reference internal" href="../tutorial/index.html">教程</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">API Reference</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="core.html">Core</a></li>
<li class="toctree-l2"><a class="reference internal" href="cli.html">Command Line Interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="distributions.html">Distributions</a></li>
<li class="toctree-l2"><a class="reference internal" href="exceptions.html">Exceptions</a></li>
<li class="toctree-l2"><a class="reference internal" href="importance.html">Hyperparameter Importance</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Integration</a></li>
<li class="toctree-l2"><a class="reference internal" href="logging.html">Logging</a></li>
<li class="toctree-l2"><a class="reference internal" href="multi_objective/index.html">Multi-objective</a></li>
<li class="toctree-l2"><a class="reference internal" href="pruners.html">Pruners</a></li>
<li class="toctree-l2"><a class="reference internal" href="samplers.html">Samplers</a></li>
<li class="toctree-l2"><a class="reference internal" href="storages.html">Storages</a></li>
<li class="toctree-l2"><a class="reference internal" href="structs.html">Structs</a></li>
<li class="toctree-l2"><a class="reference internal" href="study.html">Study</a></li>
<li class="toctree-l2"><a class="reference internal" href="trial.html">Trial</a></li>
<li class="toctree-l2"><a class="reference internal" href="visualization.html">Visualization</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../faq.html">常见问题</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">Optuna</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="index.html">API Reference</a> &raquo;</li>
        
      <li>Integration</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/reference/integration.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <span class="target" id="module-optuna.integration"></span><div class="section" id="integration">
<h1>Integration<a class="headerlink" href="#integration" title="永久链接至标题">¶</a></h1>
<dl class="py class">
<dt id="optuna.integration.ChainerPruningExtension">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">ChainerPruningExtension</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">trial</span></em>, <em class="sig-param"><span class="n">observation_key</span></em>, <em class="sig-param"><span class="n">pruner_trigger</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/chainer.html#ChainerPruningExtension"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.ChainerPruningExtension" title="永久链接至目标">¶</a></dt>
<dd><p>用于对无望 trial 剪枝的 Chainer 扩展。</p>
<p>如果你想添加一个 <a class="reference external" href="https://docs.chainer.org/en/stable/reference/generated/chainer.training.Trainer.html">Chainer Trainer</a> 的监测验证集精确度的扩展的话，请参考  <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/pruning/chainer_integration.py">the example</a> 。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>trial</strong> -- 对应于目标函数本次求值的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>。</p></li>
<li><p><strong>observation_key</strong> -- Pruning 的求值度量，比如 <code class="docutils literal notranslate"><span class="pre">main/loss</span></code> 和 <code class="docutils literal notranslate"><span class="pre">validation/main/accuracy</span></code> 。具体请参考 <cite>chainer.Reporter reference &lt;https://docs.chainer.org/en/stable/reference/</cite></p></li>
<li><p><strong>pruner_trigger</strong> -- 执行剪枝的 trigger。<code class="docutils literal notranslate"><span class="pre">pruner_trigger</span></code>  是一个`IntervalTrigger &lt;<a class="reference external" href="https://docs.chainer.org/en/stable/reference/generated/">https://docs.chainer.org/en/stable/reference/generated/</a> chainer.training.triggers.IntervalTrigger.html&gt;`_ 或者 <a class="reference external" href="https://docs.chainer.org/en/stable/reference/generated/chainer.training.triggers.ManualScheduleTrigger.html">ManualScheduleTrigger</a> 的实例。 <a class="reference external" href="https://docs.chainer.org/en/stable/reference/generated/chainer.training.triggers.IntervalTrigger.html">IntervalTrigger</a> 可以通过一个由间隔长度和单位构成的元组来指定，比如 <code class="docutils literal notranslate"><span class="pre">(1,</span> <span class="pre">'epoch')</span></code>。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt id="optuna.integration.ChainerMNStudy">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">ChainerMNStudy</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">study</span></em>, <em class="sig-param"><span class="n">comm</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/chainermn.html#ChainerMNStudy"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.ChainerMNStudy" title="永久链接至目标">¶</a></dt>
<dd><p>一个将 Optuna 并入 CHainerMN 的 <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> wrapper。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<p><code class="xref py py-class docutils literal notranslate"><span class="pre">ChainerMNStudy</span></code> 提供了和  <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 一样的接口。更多细节请参考 <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">optuna.study.Study</span></code></a>。</p>
</div>
<p>如果你想优化一个用 ChainerMN 写的神经网络目标函数的话，请参考 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/pruning/chainermn_integration.py">the example</a>。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>study</strong> -- <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 对象。</p></li>
<li><p><strong>comm</strong> -- A <a class="reference external" href="https://docs.chainer.org/en/stable/chainermn/reference/index.html#communicators">ChainerMN communicator</a>.</p></li>
</ul>
</dd>
</dl>
<dl class="py method">
<dt id="optuna.integration.ChainerMNStudy.optimize">
<code class="sig-name descname">optimize</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">func</span></em>, <em class="sig-param"><span class="n">n_trials</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">timeout</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">catch</span><span class="o">=</span><span class="default_value">()</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/chainermn.html#ChainerMNStudy.optimize"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.ChainerMNStudy.optimize" title="永久链接至目标">¶</a></dt>
<dd><p>优化目标函数。</p>
<p>除了没有 <code class="docutils literal notranslate"><span class="pre">n_jobs</span></code>  参数外，该方法提供了和 <a class="reference internal" href="study.html#optuna.study.Study.optimize" title="optuna.study.Study.optimize"><code class="xref py py-func docutils literal notranslate"><span class="pre">optuna.study.Study.optimize()</span></code></a> 一样的接口。</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt id="optuna.integration.CmaEsSampler">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">CmaEsSampler</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">x0</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">sigma0</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">cma_stds</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">seed</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">cma_opts</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">n_startup_trials</span><span class="o">=</span><span class="default_value">1</span></em>, <em class="sig-param"><span class="n">independent_sampler</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">warn_independent_sampling</span><span class="o">=</span><span class="default_value">True</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/cma.html#CmaEsSampler"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.CmaEsSampler" title="永久链接至目标">¶</a></dt>
<dd><p>使用 cma 库作为后端的 sampler。</p>
<p class="rubric">示例</p>
<p>使用 <a class="reference internal" href="#optuna.integration.CmaEsSampler" title="optuna.integration.CmaEsSampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CmaEsSampler</span></code></a> 来优化一个简单的二次函数。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">optuna</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_uniform</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="n">y</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_int</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span>

<span class="n">sampler</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">integration</span><span class="o">.</span><span class="n">CmaEsSampler</span><span class="p">()</span>
<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">(</span><span class="n">sampler</span><span class="o">=</span><span class="n">sampler</span><span class="p">)</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span>
</pre></div>
</div>
<p>注意，trial 的并行执行可能会影响 CMA-ES 的性能，尤其是在并行运行的 trial 数超过了 population size 的情况下。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>x0</strong> -- 一个包含了 CMA-ES 初始参数的字典。默认情况下使用每一个分布中的 <code class="docutils literal notranslate"><span class="pre">low</span></code> 和 <code class="docutils literal notranslate"><span class="pre">high</span></code> 的平均值。关于 <code class="docutils literal notranslate"><span class="pre">x0</span></code> 的更多细节请参考 <a class="reference external" href="http://cma.gforge.inria.fr/apidocs-pycma/cma.evolution_strategy.CMAEvolutionStrategy.html">cma.CMAEvolutionStrategy</a> 。</p></li>
<li><p><strong>sigma0</strong> -- CMA-ES 的标准差。默认情况下 <code class="docutils literal notranslate"><span class="pre">sigma0</span></code> 是 <code class="docutils literal notranslate"><span class="pre">min_range</span> <span class="pre">/</span> <span class="pre">6</span></code>，其中 <code class="docutils literal notranslate"><span class="pre">min_range</span></code> 代表来搜索空间分布的最小范围。如果该分布是类别分布，那么 <code class="docutils literal notranslate"><span class="pre">min_range</span></code> 就是 <code class="docutils literal notranslate"><span class="pre">len(choices)</span> <span class="pre">-</span> <span class="pre">1</span></code>。关于 <code class="docutils literal notranslate"><span class="pre">sigma0</span></code> 的更多细节参见 <a class="reference external" href="http://cma.gforge.inria.fr/apidocs-pycma/cma.evolution_strategy.CMAEvolutionStrategy.html">cma.CMAEvolutionStrategy</a> 。</p></li>
<li><p><strong>cma_stds</strong> -- 一个包含每个参数的 sigma0 的乘数的字典。默认情况下其值是 1.0 。关于 <code class="docutils literal notranslate"><span class="pre">cma_stds</span></code> 的更多细节参见 <a class="reference external" href="http://cma.gforge.inria.fr/apidocs-pycma/cma.evolution_strategy.CMAEvolutionStrategy.html">cma.CMAEvolutionStrategy</a> 。</p></li>
<li><p><strong>seed</strong> -- CMA-ES 的随机数种子。</p></li>
<li><p><strong>cma_opts</strong> -- 向 <a class="reference external" href="http://cma.gforge.inria.fr/apidocs-pycma/cma.evolution_strategy.CMAEvolutionStrategy.html">cma.CMAEvolutionStrategy</a> 构造函数传递的选项。注意，<code class="docutils literal notranslate"><span class="pre">cma_opts</span></code> 中的 <code class="docutils literal notranslate"><span class="pre">BoundaryHandler</span></code>, <code class="docutils literal notranslate"><span class="pre">bounds</span></code>, <code class="docutils literal notranslate"><span class="pre">CMA_stds</span></code> 和 <code class="docutils literal notranslate"><span class="pre">seed</span></code> 都会被忽略，因为它是通过 <a class="reference internal" href="#optuna.integration.CmaEsSampler" title="optuna.integration.CmaEsSampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CmaEsSampler</span></code></a>  自动添加的。</p></li>
<li><p><strong>n_startup_trials</strong> -- 在同一个 study 中指定数目的 trial 完成之前，采用的都是独立采样而不是 CMA-ES 算法采样。</p></li>
<li><p><strong>independent_sampler</strong> -- 一个用于独立采样的 <a class="reference internal" href="samplers.html#optuna.samplers.BaseSampler" title="optuna.samplers.BaseSampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseSampler</span></code></a> 实例。那些不包含在相对搜索空间内的参数都通过它来采样。 <a class="reference internal" href="#optuna.integration.CmaEsSampler" title="optuna.integration.CmaEsSampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">CmaEsSampler</span></code></a> 的搜索空间是通过 <a class="reference internal" href="samplers.html#optuna.samplers.intersection_search_space" title="optuna.samplers.intersection_search_space"><code class="xref py py-func docutils literal notranslate"><span class="pre">intersection_search_space()</span></code></a> 来确定的。如果设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code></a> 的话，默认会使用 <a class="reference internal" href="samplers.html#optuna.samplers.RandomSampler" title="optuna.samplers.RandomSampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">RandomSampler</span></code></a> 。.. seealso::     <a class="reference internal" href="samplers.html#module-optuna.samplers" title="optuna.samplers"><code class="xref py py-class docutils literal notranslate"><span class="pre">optuna.samplers</span></code></a> 模块提供了 内置的独立 sampler，比如 <a class="reference internal" href="samplers.html#optuna.samplers.RandomSampler" title="optuna.samplers.RandomSampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">RandomSampler</span></code></a> 和     <a class="reference internal" href="samplers.html#optuna.samplers.TPESampler" title="optuna.samplers.TPESampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">TPESampler</span></code></a>.</p></li>
<li><p><strong>warn_independent_sampling</strong> -- 如果该选项是 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的话，当参数值是通过一个独立 sampler 来采样时，它会触发一个警告信息。注意，在每一个 study 中的第一个 trial总是通过独立 sampler 来采样的，所以此时不会触发警报信息。</p></li>
</ul>
</dd>
</dl>
<dl class="py method">
<dt id="optuna.integration.CmaEsSampler.reseed_rng">
<code class="sig-name descname">reseed_rng</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)">None</a><a class="reference internal" href="../_modules/optuna/integration/cma.html#CmaEsSampler.reseed_rng"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.CmaEsSampler.reseed_rng" title="永久链接至目标">¶</a></dt>
<dd><p>重置随机数生成器的种子。</p>
<p>当 trial 是以 <code class="docutils literal notranslate"><span class="pre">n_jobs&gt;1</span></code> 的选项被并行执行时，该方法会被 <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 调用。在这种情况下，sampler 实例和随机数生成器的状态都会被复制，因此它们会产生同样的值，为了避免这种情况，该方法给每一个随机数生成器分配一个不同的种子。</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt id="optuna.integration.FastAIPruningCallback">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">FastAIPruningCallback</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">learn</span></em>, <em class="sig-param"><span class="n">trial</span></em>, <em class="sig-param"><span class="n">monitor</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/fastai.html#FastAIPruningCallback"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.FastAIPruningCallback" title="永久链接至目标">¶</a></dt>
<dd><p>用于清除 FastAI 中无望 trial 的回调函数。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>该回调函数是为 fastai&lt;2.0，而不是 fastai/fastai_dev 版本设计的。</p>
</div>
<p>如果你想添加一个监测 <code class="docutils literal notranslate"><span class="pre">Learner</span></code> 的验证集 loss 的 pruner 的话，请参考 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/fastai_simple.py">the example</a> 。</p>
<p class="rubric">示例</p>
<p>向 <code class="docutils literal notranslate"><span class="pre">learn.fit</span></code> 和 <code class="docutils literal notranslate"><span class="pre">learn.fit_one_cycle</span></code> 注入一个 pruning 回调。</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">learn</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">n_epochs</span><span class="p">,</span> <span class="n">callbacks</span><span class="o">=</span><span class="p">[</span><span class="n">FastAIPruningCallback</span><span class="p">(</span><span class="n">learn</span><span class="p">,</span> <span class="n">trial</span><span class="p">,</span> <span class="s1">&#39;valid_loss&#39;</span><span class="p">)])</span>
<span class="n">learn</span><span class="o">.</span><span class="n">fit_one_cycle</span><span class="p">(</span>
    <span class="n">n_epochs</span><span class="p">,</span> <span class="n">cyc_len</span><span class="p">,</span> <span class="n">max_lr</span><span class="p">,</span>
    <span class="n">callbacks</span><span class="o">=</span><span class="p">[</span><span class="n">FastAIPruningCallback</span><span class="p">(</span><span class="n">learn</span><span class="p">,</span> <span class="n">trial</span><span class="p">,</span> <span class="s1">&#39;valid_loss&#39;</span><span class="p">)])</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>learn</strong> -- <a class="reference external" href="https://docs.fast.ai/basic_train.html#Learner">fastai.basic_train.Learner</a>.</p></li>
<li><p><strong>trial</strong> -- 对应于目标函数本次求值的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>。</p></li>
<li><p><strong>monitor</strong> -- Pruning 的求值度量，比如 <code class="docutils literal notranslate"><span class="pre">valid_loss</span></code> 和 <code class="docutils literal notranslate"><span class="pre">Accuracy</span></code> 。具体请参考 <a class="reference external" href="https://docs.fast.ai/callback.html#Callback">fastai.Callback reference</a> 。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt id="optuna.integration.PyTorchIgnitePruningHandler">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">PyTorchIgnitePruningHandler</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">trial</span></em>, <em class="sig-param"><span class="n">metric</span></em>, <em class="sig-param"><span class="n">trainer</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/pytorch_ignite.html#PyTorchIgnitePruningHandler"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.PyTorchIgnitePruningHandler" title="永久链接至目标">¶</a></dt>
<dd><p>用于清除无望 trial 的 PyTorch Ignite handler。</p>
<p>如果你想添加一个监测验证集 accuracy 的 pruner 的话，请参考 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/pytorch_ignite_simple.py">the example</a>。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>trial</strong> -- 对应于目标函数本次求值的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>。</p></li>
<li><p><strong>metric</strong> -- 用于 pruning 的度量名，比如 <code class="docutils literal notranslate"><span class="pre">accuracy</span></code> 和 <code class="docutils literal notranslate"><span class="pre">loss</span></code>.</p></li>
<li><p><strong>trainer</strong> -- PyTorch Ignite 的 trainer engine。更多细节请参考 <a class="reference external" href="https://pytorch.org/ignite/engine.html#ignite.engine.Engine">ignite.engine.Engine reference</a> 。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt id="optuna.integration.KerasPruningCallback">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">KerasPruningCallback</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">trial</span></em>, <em class="sig-param"><span class="n">monitor</span></em>, <em class="sig-param"><span class="n">interval</span><span class="o">=</span><span class="default_value">1</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/keras.html#KerasPruningCallback"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.KerasPruningCallback" title="永久链接至目标">¶</a></dt>
<dd><p>用于清除无望 trial 的 Keras 回调函数。</p>
<p>如果你想添加一个监测验证集 accuracy 的 pruner 的话，请参考 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/pruning/keras_integration.py">the example</a> 。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>trial</strong> -- 对应于目标函数本次求值的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>。</p></li>
<li><p><strong>monitor</strong> -- Pruning 的求值度量，比如 <code class="docutils literal notranslate"><span class="pre">val_loss</span></code> 和 <code class="docutils literal notranslate"><span class="pre">val_accuracy</span></code> 。具体请参考 <a class="reference external" href="https://keras.io/callbacks/#callback">keras.Callback reference</a> 。</p></li>
<li><p><strong>interval</strong> -- 每到第 n 个 epoch 检查是否要清除该 trial。默认情况下 <code class="docutils literal notranslate"><span class="pre">interval=1</span></code> 此时每个 epoch 之后pruning 都会执行一次。增加 <code class="docutils literal notranslate"><span class="pre">interval</span></code> 可以先执行数个 epoch，然后再执行 pruning。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt id="optuna.integration.LightGBMPruningCallback">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">LightGBMPruningCallback</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">trial</span></em>, <em class="sig-param"><span class="n">metric</span></em>, <em class="sig-param"><span class="n">valid_name</span><span class="o">=</span><span class="default_value">'valid_0'</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/lightgbm.html#LightGBMPruningCallback"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.LightGBMPruningCallback" title="永久链接至目标">¶</a></dt>
<dd><p>用于清除无望 trial 的 LightGBM 回调函数。</p>
<p>如果你想添加一个监测 LightGBM 模型的 AUC 的 pruner 的话，请参考 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/pruning/lightgbm_integration.py">the example</a> 。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>trial</strong> -- 对应于目标函数本次求值的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>。</p></li>
<li><p><strong>metric</strong> -- Pruning 的求值度量，比如 <code class="docutils literal notranslate"><span class="pre">binary_error</span></code> 和 <code class="docutils literal notranslate"><span class="pre">multi_error</span></code> 。具体请参考 <a class="reference external" href="https://lightgbm.readthedocs.io/en/latest/Parameters.html#metric">LightGBM reference</a> 。</p></li>
<li><p><strong>valid_name</strong> -- 目标验证名。验证名是通过 <a class="reference external" href="https://lightgbm.readthedocs.io/en/latest/Python-API.html#lightgbm.train">train method</a> 的 <code class="docutils literal notranslate"><span class="pre">valid_names</span></code> 选项来设定的。如果省略的话就采用 <cite>valid_0`</cite>，它是第一个验证的默认名。注意，如果你没有调用 train 方法而是调用了 <a class="reference external" href="https://lightgbm.readthedocs.io/en/latest/Python-API.html#lightgbm.cv">cv method</a> 的话，该参数会被忽略。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py function">
<dt id="optuna.integration.lightgbm.train">
<code class="sig-prename descclassname">optuna.integration.lightgbm.</code><code class="sig-name descname">train</code><span class="sig-paren">(</span><em class="sig-param"><span class="o">*</span><span class="n">args</span><span class="p">:</span> <span class="n">Any</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Any</span></em><span class="sig-paren">)</span> &#x2192; Any<a class="reference internal" href="../_modules/optuna/integration/_lightgbm_tuner.html#train"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.lightgbm.train" title="永久链接至目标">¶</a></dt>
<dd><p>用于调整超参数的 LightGBM Training API 的 wrapper。</p>
<p>它逐步调整重要的超参数（比如 <code class="docutils literal notranslate"><span class="pre">min_child_samples</span></code> 和 <code class="docutils literal notranslate"><span class="pre">feature_fraction</span></code>），是 <a class="reference external" href="https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.train.html">lightgbm.train()</a> 的一个非正式替代品。参见 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/lightgbm_tuner_simple.py">a simple example of LightGBM Tuner</a> which optimizes the validation log loss of cancer detection.</p>
<p><a class="reference internal" href="#optuna.integration.lightgbm.train" title="optuna.integration.lightgbm.train"><code class="xref py py-func docutils literal notranslate"><span class="pre">train()</span></code></a> 是 <a class="reference internal" href="#optuna.integration.lightgbm.LightGBMTuner" title="optuna.integration.lightgbm.LightGBMTuner"><code class="xref py py-class docutils literal notranslate"><span class="pre">LightGBMTuner</span></code></a> 的 wrapper。如果想使用 suspended/resumed optimization 和/或 parallelization 等 Optuna 特性的话，请使用 <a class="reference internal" href="#optuna.integration.lightgbm.LightGBMTuner" title="optuna.integration.lightgbm.LightGBMTuner"><code class="xref py py-class docutils literal notranslate"><span class="pre">LightGBMTuner</span></code></a> 而不是该函数。</p>
<p>可以传入给 <a class="reference external" href="https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.train.html">lightgbm.train()</a> 的参数。</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>在 v0.18.0 中作为试验性特性引入，在未来版本中，该接口可能在没有预先告知的情况下被改变。参考 <a class="reference external" href="https://github.com/optuna/optuna/releases/tag/v0.18.0">https://github.com/optuna/optuna/releases/tag/v0.18.0</a>.</p>
</div>
</dd></dl>

<dl class="py class">
<dt id="optuna.integration.lightgbm.LightGBMTuner">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.lightgbm.</code><code class="sig-name descname">LightGBMTuner</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">params</span><span class="p">:</span> <span class="n">Dict<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a><span class="p">, </span>Any<span class="p">]</span></span></em>, <em class="sig-param"><span class="n">train_set</span><span class="p">:</span> <span class="n">lgb.Dataset</span></em>, <em class="sig-param"><span class="n">num_boost_round</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a></span> <span class="o">=</span> <span class="default_value">1000</span></em>, <em class="sig-param"><span class="n">valid_sets</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span>VALID_SET_TYPE<span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">valid_names</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span>Any<span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">fobj</span><span class="p">:</span> <span class="n">Optional[Callable[[...], Any]]</span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">feval</span><span class="p">:</span> <span class="n">Optional[Callable[[...], Any]]</span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">feature_name</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a></span> <span class="o">=</span> <span class="default_value">'auto'</span></em>, <em class="sig-param"><span class="n">categorical_feature</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a></span> <span class="o">=</span> <span class="default_value">'auto'</span></em>, <em class="sig-param"><span class="n">early_stopping_rounds</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">evals_result</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span>Dict<span class="p">[</span>Any<span class="p">, </span>Any<span class="p">]</span><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">verbose_eval</span><span class="p">:</span> <span class="n">Union[bool, int, None]</span> <span class="o">=</span> <span class="default_value">True</span></em>, <em class="sig-param"><span class="n">learning_rates</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span>List<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(在 Python v3.8)">float</a><span class="p">]</span><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">keep_training_booster</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.8)">bool</a><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">False</span></em>, <em class="sig-param"><span class="n">callbacks</span><span class="p">:</span> <span class="n">Optional[List[Callable[[...], Any]]]</span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">time_budget</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">sample_size</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">study</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study">optuna.study.Study</a><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">optuna_callbacks</span><span class="p">:</span> <span class="n">Optional[List[Callable[[optuna.study.Study, optuna.trial._frozen.FrozenTrial], None]]]</span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">model_dir</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">verbosity</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">1</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/_lightgbm_tuner/optimize.html#LightGBMTuner"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.lightgbm.LightGBMTuner" title="永久链接至目标">¶</a></dt>
<dd><p>LightGBM 的超参数调节器。</p>
<p>它逐步调整下列超参数：<code class="docutils literal notranslate"><span class="pre">lambda_l1</span></code>, <code class="docutils literal notranslate"><span class="pre">lambda_l2</span></code>, <code class="docutils literal notranslate"><span class="pre">num_leaves</span></code>, <code class="docutils literal notranslate"><span class="pre">feature_fraction</span></code>, <code class="docutils literal notranslate"><span class="pre">bagging_fraction</span></code>, <code class="docutils literal notranslate"><span class="pre">bagging_freq</span></code> 和 <code class="docutils literal notranslate"><span class="pre">min_child_samples</span></code>.</p>
<p>你可以在 <a class="reference external" href="https://medium.com/optuna/lightgbm-tuner-new-optuna-integration-for-hyperparameter-optimization-8b7095e99258">this blog article</a> 中找到该算法和其基准测试的细节。它是 <a class="reference external" href="https://www.kaggle.com/confirm">Kohei Ozaki</a> 由写的，Kohei Ozaki 是一个 Kaggle Grandmaster。</p>
<p>可以传入给 <a class="reference external" href="https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.train.html">lightgbm.train()</a> 的参数。专属 <a class="reference internal" href="#optuna.integration.lightgbm.LightGBMTuner" title="optuna.integration.lightgbm.LightGBMTuner"><code class="xref py py-class docutils literal notranslate"><span class="pre">LightGBMTuner</span></code></a>  的参数列在下面了：</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>time_budget</strong> -- 以秒计算的调参时间预算。</p></li>
<li><p><strong>study</strong> -- 一个用于存储优化结果的 <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 实例。其中的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> 由下列用户属性：<code class="docutils literal notranslate"><span class="pre">elapsed_secs</span></code>  是自优化开始以来消耗的时间。<code class="docutils literal notranslate"><span class="pre">average_iteration_time</span></code> 是一个 trial 中训练一个 booster 模型所需要的平均迭代时间。<code class="docutils literal notranslate"><span class="pre">lgbm_params</span></code> 是一个 JSON 序列化过的，存储 trial 中采用的 LightGBM 的参数的字典。</p></li>
<li><p><strong>optuna_callbacks</strong> -- 在每个trial 结束后触发的 Optuna 回调函数列表。其中每个函数必须接受两个下面这种顺序和类型的参数： <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> and <code class="xref py py-class docutils literal notranslate"><span class="pre">FrozenTrial</span></code>。注意，这不是 <a class="reference external" href="https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.train.html">lightgbm.train()</a> 的 <code class="docutils literal notranslate"><span class="pre">callbacks</span></code> 参数。</p></li>
<li><p><strong>model_dir</strong> -- 用于存储 booster 的目录。默认情况下它是 <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code></a>，也不会存储 booster。如果你想在分布式的环境下获取 <code class="xref py py-meth docutils literal notranslate"><span class="pre">get_best_booster()</span></code> 的话，请设置共享目录（比如 NFS 上的目录）。否则，它会抛出 <a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">ValueError</span></code></a> 错误。booster 的文件名是有如下形式：<code class="docutils literal notranslate"><span class="pre">{model_dir}/{trial_number}.pkl</span></code> (比如 <code class="docutils literal notranslate"><span class="pre">./boosters/0.pkl</span></code>)。</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>在 v1.5.0 中作为试验性特性引入，在未来版本中，该接口可能在没有预先告知的情况下被改变。参考 <a class="reference external" href="https://github.com/optuna/optuna/releases/tag/v1.5.0">https://github.com/optuna/optuna/releases/tag/v1.5.0</a>.</p>
</div>
<dl class="py method">
<dt id="optuna.integration.lightgbm.LightGBMTuner.best_booster">
<em class="property">property </em><code class="sig-name descname">best_booster</code><a class="headerlink" href="#optuna.integration.lightgbm.LightGBMTuner.best_booster" title="永久链接至目标">¶</a></dt>
<dd><p>返回最佳 booster。</p>
<div class="deprecated">
<p><span class="versionmodified deprecated">1.4.0 版后已移除: </span>请通过 <a class="reference internal" href="#optuna.integration.lightgbm.LightGBMTuner.get_best_booster" title="optuna.integration.lightgbm.LightGBMTuner.get_best_booster"><code class="xref py py-class docutils literal notranslate"><span class="pre">get_best_booster</span></code></a> 来获取最佳 booster。</p>
</div>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.lightgbm.LightGBMTuner.best_params">
<em class="property">property </em><code class="sig-name descname">best_params</code><a class="headerlink" href="#optuna.integration.lightgbm.LightGBMTuner.best_params" title="永久链接至目标">¶</a></dt>
<dd><p>返回最佳 booster 的参数。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.lightgbm.LightGBMTuner.best_score">
<em class="property">property </em><code class="sig-name descname">best_score</code><a class="headerlink" href="#optuna.integration.lightgbm.LightGBMTuner.best_score" title="永久链接至目标">¶</a></dt>
<dd><p>返回最佳 booster 的分数。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.lightgbm.LightGBMTuner.get_best_booster">
<code class="sig-name descname">get_best_booster</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; lgb.Booster<a class="reference internal" href="../_modules/optuna/integration/_lightgbm_tuner/optimize.html#LightGBMTuner.get_best_booster"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.lightgbm.LightGBMTuner.get_best_booster" title="永久链接至目标">¶</a></dt>
<dd><p>返回最佳 booster。</p>
<p>如果无法找到最佳 booster 的话，会抛出 <a class="reference external" href="https://docs.python.org/3/library/exceptions.html#ValueError" title="(在 Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">ValueError</span></code></a> 。为了避免这种情况，如果你要并行运行 trial 或者恢复调参的话，请通过设置 <code class="xref py py-meth docutils literal notranslate"><span class="pre">__init__()</span></code> 的 <code class="docutils literal notranslate"><span class="pre">model_dir</span></code> 参数来存储 booster。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.lightgbm.LightGBMTuner.run">
<code class="sig-name descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)">None</a><a class="headerlink" href="#optuna.integration.lightgbm.LightGBMTuner.run" title="永久链接至目标">¶</a></dt>
<dd><p>用给定的参数来进行超参数调参。</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt id="optuna.integration.lightgbm.LightGBMTunerCV">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.lightgbm.</code><code class="sig-name descname">LightGBMTunerCV</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">params</span><span class="p">:</span> <span class="n">Dict<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a><span class="p">, </span>Any<span class="p">]</span></span></em>, <em class="sig-param"><span class="n">train_set</span><span class="p">:</span> <span class="n">lgb.Dataset</span></em>, <em class="sig-param"><span class="n">num_boost_round</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a></span> <span class="o">=</span> <span class="default_value">1000</span></em>, <em class="sig-param"><span class="n">folds</span><span class="p">:</span> <span class="n">Union[Generator[Tuple[int, int], None, None], Iterator[Tuple[int, int]], BaseCrossValidator, None]</span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">nfold</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a></span> <span class="o">=</span> <span class="default_value">5</span></em>, <em class="sig-param"><span class="n">stratified</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.8)">bool</a></span> <span class="o">=</span> <span class="default_value">True</span></em>, <em class="sig-param"><span class="n">shuffle</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.8)">bool</a></span> <span class="o">=</span> <span class="default_value">True</span></em>, <em class="sig-param"><span class="n">fobj</span><span class="p">:</span> <span class="n">Optional[Callable[[...], Any]]</span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">feval</span><span class="p">:</span> <span class="n">Optional[Callable[[...], Any]]</span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">feature_name</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a></span> <span class="o">=</span> <span class="default_value">'auto'</span></em>, <em class="sig-param"><span class="n">categorical_feature</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a></span> <span class="o">=</span> <span class="default_value">'auto'</span></em>, <em class="sig-param"><span class="n">early_stopping_rounds</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">fpreproc</span><span class="p">:</span> <span class="n">Optional[Callable[[...], Any]]</span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">verbose_eval</span><span class="p">:</span> <span class="n">Union[bool, int, None]</span> <span class="o">=</span> <span class="default_value">True</span></em>, <em class="sig-param"><span class="n">show_stdv</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#bool" title="(在 Python v3.8)">bool</a></span> <span class="o">=</span> <span class="default_value">True</span></em>, <em class="sig-param"><span class="n">seed</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a></span> <span class="o">=</span> <span class="default_value">0</span></em>, <em class="sig-param"><span class="n">callbacks</span><span class="p">:</span> <span class="n">Optional[List[Callable[[...], Any]]]</span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">time_budget</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">sample_size</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">study</span><span class="p">:</span> <span class="n">Optional<span class="p">[</span><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study">optuna.study.Study</a><span class="p">]</span></span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">optuna_callbacks</span><span class="p">:</span> <span class="n">Optional[List[Callable[[optuna.study.Study, optuna.trial._frozen.FrozenTrial], None]]]</span> <span class="o">=</span> <span class="default_value">None</span></em>, <em class="sig-param"><span class="n">verbosity</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/functions.html#int" title="(在 Python v3.8)">int</a></span> <span class="o">=</span> <span class="default_value">1</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/_lightgbm_tuner/optimize.html#LightGBMTunerCV"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.lightgbm.LightGBMTunerCV" title="永久链接至目标">¶</a></dt>
<dd><p>带有交叉验证的 LightGBM 超参数 tuner。</p>
<p>它采用了和 <a class="reference internal" href="#optuna.integration.lightgbm.LightGBMTuner" title="optuna.integration.lightgbm.LightGBMTuner"><code class="xref py py-class docutils literal notranslate"><span class="pre">LightGBMTuner</span></code></a> 同样的逐步措施。<a class="reference internal" href="#optuna.integration.lightgbm.LightGBMTunerCV" title="optuna.integration.lightgbm.LightGBMTunerCV"><code class="xref py py-class docutils literal notranslate"><span class="pre">LightGBMTunerCV</span></code></a> 通过触发 <a class="reference external" href="https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.cv.html">lightgbm.cv()</a>  来训练和验证 booster，而 <a class="reference internal" href="#optuna.integration.lightgbm.LightGBMTuner" title="optuna.integration.lightgbm.LightGBMTuner"><code class="xref py py-class docutils literal notranslate"><span class="pre">LightGBMTuner</span></code></a> 则采用 <a class="reference external" href="https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.train.html">lightgbm.train()</a>。在 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/lightgbm_tuner_cv.py">a simple example</a> 这里可以看到一个在癌症检测上优化验证集上 log loss 的例子。</p>
<p>除了 <code class="docutils literal notranslate"><span class="pre">metrics</span></code>, <code class="docutils literal notranslate"><span class="pre">init_model</span></code> 和 <code class="docutils literal notranslate"><span class="pre">eval_train_metric</span></code>，其他参数都可以传递给 <a class="reference external" href="https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.cv.html">lightgbm.cv()</a> 。<a class="reference internal" href="#optuna.integration.lightgbm.LightGBMTunerCV" title="optuna.integration.lightgbm.LightGBMTunerCV"><code class="xref py py-class docutils literal notranslate"><span class="pre">LightGBMTunerCV</span></code></a>  独有的参数列在下面了：</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>time_budget</strong> -- 以秒计算的调参时间预算。</p></li>
<li><p><strong>study</strong> -- 一个用于存储优化结果的 <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 实例。其中的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a> 由下列用户属性：<code class="docutils literal notranslate"><span class="pre">elapsed_secs</span></code>  是自优化开始以来消耗的时间。<code class="docutils literal notranslate"><span class="pre">average_iteration_time</span></code> 是一个 trial 中训练一个 booster 模型所需要的平均迭代时间。<code class="docutils literal notranslate"><span class="pre">lgbm_params</span></code> 是一个 JSON 序列化过的，存储 trial 中采用的 LightGBM 的参数的字典。</p></li>
<li><p><strong>optuna_callbacks</strong> -- 在每个trial 结束后触发的 Optuna 回调函数列表。其中每个函数必须接受两个下面这种顺序和类型的参数： <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> and <code class="xref py py-class docutils literal notranslate"><span class="pre">FrozenTrial</span></code>。注意，这不是 <a class="reference external" href="https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.train.html">lightgbm.train()</a> 的 <code class="docutils literal notranslate"><span class="pre">callbacks</span></code> 参数。</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>在 v1.5.0 中作为试验性特性引入，在未来版本中，该接口可能在没有预先告知的情况下被改变。参考 <a class="reference external" href="https://github.com/optuna/optuna/releases/tag/v1.5.0">https://github.com/optuna/optuna/releases/tag/v1.5.0</a>.</p>
</div>
<dl class="py method">
<dt id="optuna.integration.lightgbm.LightGBMTunerCV.best_params">
<em class="property">property </em><code class="sig-name descname">best_params</code><a class="headerlink" href="#optuna.integration.lightgbm.LightGBMTunerCV.best_params" title="永久链接至目标">¶</a></dt>
<dd><p>返回最佳 booster 的参数。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.lightgbm.LightGBMTunerCV.best_score">
<em class="property">property </em><code class="sig-name descname">best_score</code><a class="headerlink" href="#optuna.integration.lightgbm.LightGBMTunerCV.best_score" title="永久链接至目标">¶</a></dt>
<dd><p>返回最佳 booster 的分数。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.lightgbm.LightGBMTunerCV.run">
<code class="sig-name descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)">None</a><a class="headerlink" href="#optuna.integration.lightgbm.LightGBMTunerCV.run" title="永久链接至目标">¶</a></dt>
<dd><p>用给定的参数来进行超参数调参。</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt id="optuna.integration.MLflowCallback">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">MLflowCallback</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">tracking_uri</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">metric_name</span><span class="o">=</span><span class="default_value">'value'</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/mlflow.html#MLflowCallback"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.MLflowCallback" title="永久链接至目标">¶</a></dt>
<dd><p>用 MLflow 来追踪 Optuna trial 的回调函数。</p>
<p>该回调函数添加被 Optuna 追踪的相关信息到 MLflow 中。而对应的 MLflow 实验会按照 Optuna study 名来命名。</p>
<p class="rubric">示例</p>
<p>给 Optuna 优化添加一个 MLflow 回调函数。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">optuna</span>
<span class="kn">from</span> <span class="nn">optuna.integration.mlflow</span> <span class="kn">import</span> <span class="n">MLflowCallback</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_uniform</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="o">-</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
    <span class="k">return</span> <span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="mi">2</span><span class="p">)</span> <span class="o">**</span> <span class="mi">2</span>

<span class="n">mlflc</span> <span class="o">=</span> <span class="n">MLflowCallback</span><span class="p">(</span>
    <span class="n">tracking_uri</span><span class="o">=</span><span class="n">YOUR_TRACKING_URI</span><span class="p">,</span>
    <span class="n">metric_name</span><span class="o">=</span><span class="s1">&#39;my metric score&#39;</span><span class="p">,</span>
<span class="p">)</span>

<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">(</span><span class="n">study_name</span><span class="o">=</span><span class="s1">&#39;my_study&#39;</span><span class="p">)</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">callbacks</span><span class="o">=</span><span class="p">[</span><span class="n">mlflc</span><span class="p">])</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>tracking_uri</strong> -- MLflow tracking server 的 URI。更多细节请参考 <a class="reference external" href="https://www.mlflow.org/docs/latest/python_api/mlflow.html#mlflow.set_tracking_uri">mlflow.set_tracking_uri</a>。</p></li>
<li><p><strong>metric_name</strong> -- 度量名。由于度量本身只是一个数字，所以可以用 <cite>metric_name</cite> 为它命名，这样好让你之后知道它是 roc-auc 还是 accuracy。</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>在 v1.4.0 中作为试验性特性引入，在未来版本中，该接口可能在没有预先告知的情况下被改变。参考 <a class="reference external" href="https://github.com/optuna/optuna/releases/tag/v1.4.0">https://github.com/optuna/optuna/releases/tag/v1.4.0</a>.</p>
</div>
</dd></dl>

<dl class="py class">
<dt id="optuna.integration.MXNetPruningCallback">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">MXNetPruningCallback</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">trial</span></em>, <em class="sig-param"><span class="n">eval_metric</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/mxnet.html#MXNetPruningCallback"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.MXNetPruningCallback" title="永久链接至目标">¶</a></dt>
<dd><p>用于清除无望 trial 的 MXNet 回调函数。</p>
<p>如果你想添加一个监测 accuracy 的 pruner 的话，请参考 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/pruning/mxnet_integration.py">the example</a> 。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>trial</strong> -- 对应于目标函数本次求值的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>。</p></li>
<li><p><strong>eval_metric</strong> -- 用于 pruning 的求值度量名，比如 <code class="docutils literal notranslate"><span class="pre">cross-entropy</span></code> 和 <code class="docutils literal notranslate"><span class="pre">accuracy</span></code>。如果使用像 mxnet.metrics.Accuracy 这样的默认度量的话，就使用它的默认度量名。对于定制的度量，就使用传递给构造函数的 metric_name。更多细节请参考 <a class="reference external" href="https://mxnet.apache.org/api/python/metric/metric.html">mxnet.metrics reference</a> 。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt id="optuna.integration.PyTorchLightningPruningCallback">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">PyTorchLightningPruningCallback</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">trial</span></em>, <em class="sig-param"><span class="n">monitor</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/pytorch_lightning.html#PyTorchLightningPruningCallback"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.PyTorchLightningPruningCallback" title="永久链接至目标">¶</a></dt>
<dd><p>用于清除无望 trial 的 PyTorch Lighting 回调函数。</p>
<p>如果你想添加一个监测 accuracy 的 pruner 的话，请参考 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/pytorch_lightning_simple.py">the example</a> 。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>trial</strong> -- 对应于目标函数本次求值的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>。</p></li>
<li><p><strong>monitor</strong> -- Pruning 的求值度量，比如 <code class="docutils literal notranslate"><span class="pre">val_loss</span></code> 和 <code class="docutils literal notranslate"><span class="pre">val_acc</span></code> 。这戏的度量是通过 <code class="docutils literal notranslate"><span class="pre">pytorch_lightning.LightningModule.training_step</span></code> 或者 <code class="docutils literal notranslate"><span class="pre">pytorch_lightning.LightningModule.validation_end</span></code> 返回的字典来获得的。因此，这些度量名取决于字典的格式。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt id="optuna.integration.SkoptSampler">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">SkoptSampler</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">independent_sampler</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">warn_independent_sampling</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">skopt_kwargs</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">n_startup_trials</span><span class="o">=</span><span class="default_value">1</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/skopt.html#SkoptSampler"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.SkoptSampler" title="永久链接至目标">¶</a></dt>
<dd><p>以  Scikit-Optimize 为后端的 sampler。</p>
<p class="rubric">示例</p>
<p>用 <a class="reference internal" href="#optuna.integration.SkoptSampler" title="optuna.integration.SkoptSampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SkoptSampler</span></code></a> 来优化一个简单的二次函数。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">optuna</span>

<span class="k">def</span> <span class="nf">objective</span><span class="p">(</span><span class="n">trial</span><span class="p">):</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_uniform</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">,</span> <span class="o">-</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
    <span class="n">y</span> <span class="o">=</span> <span class="n">trial</span><span class="o">.</span><span class="n">suggest_int</span><span class="p">(</span><span class="s1">&#39;y&#39;</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span> <span class="o">+</span> <span class="n">y</span>

<span class="n">sampler</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">integration</span><span class="o">.</span><span class="n">SkoptSampler</span><span class="p">()</span>
<span class="n">study</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">create_study</span><span class="p">(</span><span class="n">sampler</span><span class="o">=</span><span class="n">sampler</span><span class="p">)</span>
<span class="n">study</span><span class="o">.</span><span class="n">optimize</span><span class="p">(</span><span class="n">objective</span><span class="p">,</span> <span class="n">n_trials</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>independent_sampler</strong> -- 一个用于独立采样的 <a class="reference internal" href="samplers.html#optuna.samplers.BaseSampler" title="optuna.samplers.BaseSampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">BaseSampler</span></code></a> 实例。那些不包含在相对搜索空间内的参数都通过它来采样。 <a class="reference internal" href="#optuna.integration.SkoptSampler" title="optuna.integration.SkoptSampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SkoptSampler</span></code></a> 的搜索空间是通过 <a class="reference internal" href="samplers.html#optuna.samplers.intersection_search_space" title="optuna.samplers.intersection_search_space"><code class="xref py py-func docutils literal notranslate"><span class="pre">intersection_search_space()</span></code></a> 来确定的。如果设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code></a> 的话，默认会使用 <a class="reference internal" href="samplers.html#optuna.samplers.RandomSampler" title="optuna.samplers.RandomSampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">RandomSampler</span></code></a> 。.. seealso::     <a class="reference internal" href="samplers.html#module-optuna.samplers" title="optuna.samplers"><code class="xref py py-class docutils literal notranslate"><span class="pre">optuna.samplers</span></code></a> 模块提供了 内置的独立 sampler，比如 <a class="reference internal" href="samplers.html#optuna.samplers.RandomSampler" title="optuna.samplers.RandomSampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">RandomSampler</span></code></a> 和     <a class="reference internal" href="samplers.html#optuna.samplers.TPESampler" title="optuna.samplers.TPESampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">TPESampler</span></code></a>.</p></li>
<li><p><strong>warn_independent_sampling</strong> -- 如果该选项是 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的话，当参数值是通过一个独立 sampler 来采样时，它会触发一个警告信息。注意，在每一个 study 中的第一个 trial总是通过独立 sampler 来采样的，所以此时不会触发警报信息。</p></li>
<li><p><strong>skopt_kwargs</strong> -- 传递给 <a class="reference external" href="https://scikit-optimize.github.io/#skopt.Optimizer">skopt.Optimizer</a> 的构造函数的参数。注意 <code class="docutils literal notranslate"><span class="pre">skopt_kwargs</span></code> 中的 <code class="docutils literal notranslate"><span class="pre">dimensions</span></code> 参数会被忽略，因为它是通过 <a class="reference internal" href="#optuna.integration.SkoptSampler" title="optuna.integration.SkoptSampler"><code class="xref py py-class docutils literal notranslate"><span class="pre">SkoptSampler</span></code></a> 自动添加的。</p></li>
<li><p><strong>n_startup_trials</strong> -- 在同一个 study 中指定数目的 trial 完成之前，采用的都是独立采样。</p></li>
</ul>
</dd>
</dl>
<dl class="py method">
<dt id="optuna.integration.SkoptSampler.reseed_rng">
<code class="sig-name descname">reseed_rng</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)">None</a><a class="reference internal" href="../_modules/optuna/integration/skopt.html#SkoptSampler.reseed_rng"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.SkoptSampler.reseed_rng" title="永久链接至目标">¶</a></dt>
<dd><p>重置随机数生成器的种子。</p>
<p>当 trial 是以 <code class="docutils literal notranslate"><span class="pre">n_jobs&gt;1</span></code> 的选项被并行执行时，该方法会被 <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 调用。在这种情况下，sampler 实例和随机数生成器的状态都会被复制，因此它们会产生同样的值，为了避免这种情况，该方法给每一个随机数生成器分配一个不同的种子。</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt id="optuna.integration.TensorFlowPruningHook">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">TensorFlowPruningHook</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">trial</span></em>, <em class="sig-param"><span class="n">estimator</span></em>, <em class="sig-param"><span class="n">metric</span></em>, <em class="sig-param"><span class="n">run_every_steps</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/tensorflow.html#TensorFlowPruningHook"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.TensorFlowPruningHook" title="永久链接至目标">¶</a></dt>
<dd><p>用于清除无望 trial 的 TensorFlow SessionRunHook。</p>
<p>如果你想给 TensorFlow 的 estimator 添加一个 pruning hook 的话，请参考 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/pruning/tensorflow_estimator_integration.py">the example</a>。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>trial</strong> -- 对应于目标函数本次求值的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>。</p></li>
<li><p><strong>estimator</strong> -- 要使用的 estimator。</p></li>
<li><p><strong>metric</strong> -- 用于 pruning 的度量名，比如 <code class="docutils literal notranslate"><span class="pre">accuracy</span></code> 和 <code class="docutils literal notranslate"><span class="pre">loss</span></code>。</p></li>
<li><p><strong>run_every_steps</strong> -- 监测 summary 文件的步长间隔。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt id="optuna.integration.TFKerasPruningCallback">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">TFKerasPruningCallback</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">trial</span></em>, <em class="sig-param"><span class="n">monitor</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/tfkeras.html#TFKerasPruningCallback"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.TFKerasPruningCallback" title="永久链接至目标">¶</a></dt>
<dd><p>用于清除无望 trial 的 tf.keras 回调函数。</p>
<p>该回调函数是为 TensorFlow v1 和 v2 兼容设计的，但是只在 TensorFlow v1 上测试过。</p>
<p>如果你想添加一个监测 validation accuracy 的  pruning callback 的话，请参考 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/pruning/tfkeras_integration.py">the example</a>。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>trial</strong> -- 对应于目标函数本次求值的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>。</p></li>
<li><p><strong>monitor</strong> -- 用于 pruning 的度量名，比如 <code class="docutils literal notranslate"><span class="pre">val_loss</span></code> 和 <code class="docutils literal notranslate"><span class="pre">val_acc</span></code>。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt id="optuna.integration.XGBoostPruningCallback">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">XGBoostPruningCallback</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">trial</span></em>, <em class="sig-param"><span class="n">observation_key</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/xgboost.html#XGBoostPruningCallback"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.XGBoostPruningCallback" title="永久链接至目标">¶</a></dt>
<dd><p>用于清除无望 trial 的 XGBoost 回调函数。</p>
<p>如果你想添加一个监测 XGBoost  模型的 validation AUC 的  pruning callback 的话，请参考 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/pruning/xgboost_integration.py">the example</a> 。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>trial</strong> -- 对应于目标函数本次求值的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>。</p></li>
<li><p><strong>observation_key</strong> -- Pruning 的求值度量，比如 <code class="docutils literal notranslate"><span class="pre">validation-error</span></code> 和 <code class="docutils literal notranslate"><span class="pre">validation-merror</span></code> 。在使用 Scikit-Learn API 时，<code class="docutils literal notranslate"><span class="pre">observation_key</span></code> 中必须包含 <code class="docutils literal notranslate"><span class="pre">eval_set</span></code> 的索引数，比如 <code class="docutils literal notranslate"><span class="pre">validation_0-error</span></code> and <code class="docutils literal notranslate"><span class="pre">validation_0-merror</span></code>。更多细节请参考 <a class="reference external" href="https://xgboost.readthedocs.io/en/latest/parameter.html">XGBoost reference</a> 中的 <code class="docutils literal notranslate"><span class="pre">eval_metric</span></code>。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="py class">
<dt id="optuna.integration.OptunaSearchCV">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">OptunaSearchCV</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">estimator</span></em>, <em class="sig-param"><span class="n">param_distributions</span></em>, <em class="sig-param"><span class="n">cv</span><span class="o">=</span><span class="default_value">5</span></em>, <em class="sig-param"><span class="n">enable_pruning</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">error_score</span><span class="o">=</span><span class="default_value">nan</span></em>, <em class="sig-param"><span class="n">max_iter</span><span class="o">=</span><span class="default_value">1000</span></em>, <em class="sig-param"><span class="n">n_jobs</span><span class="o">=</span><span class="default_value">1</span></em>, <em class="sig-param"><span class="n">n_trials</span><span class="o">=</span><span class="default_value">10</span></em>, <em class="sig-param"><span class="n">random_state</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">refit</span><span class="o">=</span><span class="default_value">True</span></em>, <em class="sig-param"><span class="n">return_train_score</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">scoring</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">study</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">subsample</span><span class="o">=</span><span class="default_value">1.0</span></em>, <em class="sig-param"><span class="n">timeout</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">verbose</span><span class="o">=</span><span class="default_value">0</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/sklearn.html#OptunaSearchCV"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.OptunaSearchCV" title="永久链接至目标">¶</a></dt>
<dd><p>带有交叉验证的超参数搜索。</p>
<div class="admonition warning">
<p class="admonition-title">警告</p>
<p>该特性是试验性的，其接口在未来可能会改变。</p>
</div>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>estimator</strong> -- 用于拟合数据的对象。它应当用于实现  scikit-learn estimator 接口。它至少要提供 <code class="docutils literal notranslate"><span class="pre">score</span></code> 或者 <code class="docutils literal notranslate"><span class="pre">scoring</span></code>。</p></li>
<li><p><strong>param_distributions</strong> -- 键为参数值为分布的字典。这些字典应当用于实现 Optuna 的分布接口。</p></li>
<li><p><strong>cv</strong> -- 交叉验证策略。cv 的可能输入有：- 一个用于指定 CV splitter 中的 folds 个数的整数，- 一个 CV splitter，它是一个产生由索引构成的数组的 (train, validation) splits 的 iterable 对象，对于整数而言，如果 if <code class="xref py py-obj docutils literal notranslate"><span class="pre">estimator</span></code> 是一个 classifier 而 <code class="xref py py-obj docutils literal notranslate"><span class="pre">y</span></code> 是 binary 或 multiclass 的话，那么 <code class="docutils literal notranslate"><span class="pre">sklearn.model_selection.StratifiedKFold</span></code> 会被采用。否则 <code class="docutils literal notranslate"><span class="pre">sklearn.model_selection.KFold</span></code> 会被采用。</p></li>
<li><p><strong>enable_pruning</strong> -- 如果是 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的话，当 estimator 支持 <code class="docutils literal notranslate"><span class="pre">partial_fit</span></code> 时，pruning 会被执行。</p></li>
<li><p><strong>error_score</strong> -- 拟合过程中发生错误时用于指定 score 的值。如果设置成 'raise' 的话，就会抛出错误了。如果设置成数值的话，则 <code class="docutils literal notranslate"><span class="pre">sklearn.exceptions.FitFailedWarning</span></code> 会被抛出。这并不会影响 refit 步骤，因为后者总是抛出错误。</p></li>
<li><p><strong>max_iter</strong> -- epoch 数目的最大值。它只在 estimator 支持 <code class="docutils literal notranslate"><span class="pre">partial_fit</span></code> 时会被使用。</p></li>
<li><p><strong>n_jobs</strong> -- 并行运行 job 的数量。如果设置成 <code class="xref py py-obj docutils literal notranslate"><span class="pre">-1</span></code> 的话，并行 job 的数量将等于处理器核心数。</p></li>
<li><p><strong>n_trials</strong> -- trial 数量。如果设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code></a> 的话，trial 数目无上限。此时如果 <code class="xref py py-obj docutils literal notranslate"><span class="pre">timeout</span></code> 也是 <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code></a> 的话，study 会一直创建新 trial，直到接收到一个诸如 Ctrl+C 或 SIGTERM 的终止信号。这是运行时和求解质量之间的权衡。</p></li>
<li><p><strong>random_state</strong> -- 伪随机数生成器的种子。如果是整数的话，它就是被随机数生成器采用的种子。如果是 <code class="docutils literal notranslate"><span class="pre">numpy.random.RandomState</span></code> 对象的话，它就是随机数生成器本身。如果是 <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code></a> 的话，则自 <code class="docutils literal notranslate"><span class="pre">numpy.random</span></code> 中来的全局随机状态会被采用。</p></li>
<li><p><strong>refit</strong> -- 如果设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的话，将用找到的最佳超参数重新拟合一次 estimator。该 estimator 可以通过 <code class="docutils literal notranslate"><span class="pre">best_estimator_</span></code> 属性直接获得，并且可以通过 <code class="docutils literal notranslate"><span class="pre">predict</span></code> 直接使用。</p></li>
<li><p><strong>return_train_score</strong> -- 如果设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的话，训练的 score 会被包含在内。计算训练 score 是用于搞清楚超参数设定如何影响 overfitting/underfitting  之间的平衡。不过，计算训练 score 可能消耗大量计算资源，而且严格来说，它对找出能产生最佳泛化效果的超参数而言不是必要的。</p></li>
<li><p><strong>scoring</strong> -- 用于评估验证集上预测结果的字符串或者 callable 对象。如果设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code></a> 的话，estimator 上的 <code class="docutils literal notranslate"><span class="pre">score</span></code> 会被采用。</p></li>
<li><p><strong>study</strong> -- 优化任务对应的 study，如果设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code></a> 的话，就会创建一个新的 study。</p></li>
<li><p><strong>subsample</strong> -- 在超参数搜索过程中使用的样本比例，- 如果是整数的话，那么使用  <code class="docutils literal notranslate"><span class="pre">subsample</span></code> 个样本，- 如果是浮点数的话，就使用 <code class="docutils literal notranslate"><span class="pre">subsample</span></code> * <code class="docutils literal notranslate"><span class="pre">X.shape[0]</span></code> 个样本。</p></li>
<li><p><strong>timeout</strong> -- 按秒计的用于寻找合适模型的时间上限。如果设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code></a> 的话，study 将在没有时间限制的情况运行。如果此时 <code class="xref py py-obj docutils literal notranslate"><span class="pre">n_trials</span></code> 也是 <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">None</span></code></a> 的话，该 study 会一直创建新 trial，直到接收到一个诸如 Ctrl+C 或 SIGTERM 的终止信号。这是运行时和求解质量之间的权衡。</p></li>
<li><p><strong>verbose</strong> -- 冗余级别。设的越高，输出的信息越多。</p></li>
</ul>
</dd>
</dl>
<dl class="py attribute">
<dt>
<code class="sig-name descname">best_estimator\_</code></dt>
<dd><p>通过搜多确定的 estimator。它只有在 <code class="docutils literal notranslate"><span class="pre">refit</span></code> 设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的情况下可用</p>
</dd></dl>

<dl class="py attribute">
<dt>
<code class="sig-name descname">n_splits\_</code></dt>
<dd><p>交叉验证划分数</p>
</dd></dl>

<dl class="py attribute">
<dt>
<code class="sig-name descname">refit_time\_</code></dt>
<dd><p>用于再拟合最佳 estimator 的时间。它只有在 <code class="docutils literal notranslate"><span class="pre">refit</span></code> 设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的情况下可用</p>
</dd></dl>

<dl class="py attribute">
<dt>
<code class="sig-name descname">sample_indices\_</code></dt>
<dd><p>超参数搜索过程中使用过的样本索引。</p>
</dd></dl>

<dl class="py attribute">
<dt>
<code class="sig-name descname">scorer\_</code></dt>
<dd><p>Scorer function.</p>
</dd></dl>

<dl class="py attribute">
<dt>
<code class="sig-name descname">study\_</code></dt>
<dd><p>Actual study.</p>
</dd></dl>

<p class="rubric">实际案例</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">optuna</span>
<span class="kn">from</span> <span class="nn">sklearn.datasets</span> <span class="kn">import</span> <span class="n">load_iris</span>
<span class="kn">from</span> <span class="nn">sklearn.svm</span> <span class="kn">import</span> <span class="n">SVC</span>

<span class="n">clf</span> <span class="o">=</span> <span class="n">SVC</span><span class="p">(</span><span class="n">gamma</span><span class="o">=</span><span class="s1">&#39;auto&#39;</span><span class="p">)</span>
<span class="n">param_distributions</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;C&#39;</span><span class="p">:</span> <span class="n">optuna</span><span class="o">.</span><span class="n">distributions</span><span class="o">.</span><span class="n">LogUniformDistribution</span><span class="p">(</span><span class="mf">1e-10</span><span class="p">,</span> <span class="mf">1e+10</span><span class="p">)</span>
<span class="p">}</span>
<span class="n">optuna_search</span> <span class="o">=</span> <span class="n">optuna</span><span class="o">.</span><span class="n">integration</span><span class="o">.</span><span class="n">OptunaSearchCV</span><span class="p">(</span>
    <span class="n">clf</span><span class="p">,</span>
    <span class="n">param_distributions</span>
<span class="p">)</span>
<span class="n">X</span><span class="p">,</span> <span class="n">y</span> <span class="o">=</span> <span class="n">load_iris</span><span class="p">(</span><span class="n">return_X_y</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">optuna_search</span><span class="o">.</span><span class="n">fit</span><span class="p">(</span><span class="n">X</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span>
<span class="n">y_pred</span> <span class="o">=</span> <span class="n">optuna_search</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">X</span><span class="p">)</span>
</pre></div>
</div>
<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.best_index_">
<em class="property">property </em><code class="sig-name descname">best_index_</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.best_index_" title="永久链接至目标">¶</a></dt>
<dd><p>对应于最佳参数设置的索引</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.best_params_">
<em class="property">property </em><code class="sig-name descname">best_params_</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.best_params_" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 中最佳 trial 的参数。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.best_score_">
<em class="property">property </em><code class="sig-name descname">best_score_</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.best_score_" title="永久链接至目标">¶</a></dt>
<dd><p>最佳 estimator 的平均交叉验证 score。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.best_trial_">
<em class="property">property </em><code class="sig-name descname">best_trial_</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.best_trial_" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 中的最佳 trial。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.classes_">
<em class="property">property </em><code class="sig-name descname">classes_</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.classes_" title="永久链接至目标">¶</a></dt>
<dd><p>Class labels.</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.decision_function">
<em class="property">property </em><code class="sig-name descname">decision_function</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.decision_function" title="永久链接至目标">¶</a></dt>
<dd><p>在最佳 estimator 上调用 <code class="docutils literal notranslate"><span class="pre">decision_function</span></code> 。</p>
<p>它只有在对应的 estimator支持  <code class="docutils literal notranslate"><span class="pre">decision_function</span></code> 和 <code class="docutils literal notranslate"><span class="pre">refit</span></code> 设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的情况下可用。&quot;</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.fit">
<code class="sig-name descname">fit</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">X</span></em>, <em class="sig-param"><span class="n">y</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">groups</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">fit_params</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/sklearn.html#OptunaSearchCV.fit"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.OptunaSearchCV.fit" title="永久链接至目标">¶</a></dt>
<dd><p>用所有参数来跑拟合。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>X</strong> -- 训练数据</p></li>
<li><p><strong>y</strong> -- 目标变量。</p></li>
<li><p><strong>groups</strong> -- 将数据集划分成训练/测试集时给样本打的标签。</p></li>
<li><p><strong>**fit_params</strong> -- 传递给 estimator 上的 <code class="docutils literal notranslate"><span class="pre">fit</span></code> 的参数。</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p>Return self.</p>
</dd>
<dt class="field-odd">返回类型</dt>
<dd class="field-odd"><p>self</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.inverse_transform">
<em class="property">property </em><code class="sig-name descname">inverse_transform</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.inverse_transform" title="永久链接至目标">¶</a></dt>
<dd><p>调用最佳 estimator 的 <code class="docutils literal notranslate"><span class="pre">inverse_transform</span></code> 。</p>
<p>它只有在对应的 estimator支持  <code class="docutils literal notranslate"><span class="pre">inverse_transform</span></code> 和 <code class="docutils literal notranslate"><span class="pre">refit</span></code> 设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的情况下可用。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.n_trials_">
<em class="property">property </em><code class="sig-name descname">n_trials_</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.n_trials_" title="永久链接至目标">¶</a></dt>
<dd><p>trial 实际数量。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.predict">
<em class="property">property </em><code class="sig-name descname">predict</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.predict" title="永久链接至目标">¶</a></dt>
<dd><p>调用最佳 estimator 的 <code class="docutils literal notranslate"><span class="pre">predict</span></code> 。</p>
<p>它只有在对应的 estimator支持  <code class="docutils literal notranslate"><span class="pre">predict</span></code> 和 <code class="docutils literal notranslate"><span class="pre">refit</span></code> 设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的情况下可用。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.predict_log_proba">
<em class="property">property </em><code class="sig-name descname">predict_log_proba</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.predict_log_proba" title="永久链接至目标">¶</a></dt>
<dd><p>调用最佳 predict_log_proba 的 <code class="docutils literal notranslate"><span class="pre">predict</span></code> 。</p>
<p>它只有在对应的 estimator支持  <code class="docutils literal notranslate"><span class="pre">predict_log_proba</span></code> 和 <code class="docutils literal notranslate"><span class="pre">refit</span></code> 设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的情况下可用。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.predict_proba">
<em class="property">property </em><code class="sig-name descname">predict_proba</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.predict_proba" title="永久链接至目标">¶</a></dt>
<dd><p>调用最佳 estimator 的 <code class="docutils literal notranslate"><span class="pre">predict_proba</span></code> 。</p>
<p>它只有在对应的 estimator支持  <code class="docutils literal notranslate"><span class="pre">predict_proba</span></code> 和 <code class="docutils literal notranslate"><span class="pre">refit</span></code> 设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的情况下可用。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.score">
<code class="sig-name descname">score</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">X</span></em>, <em class="sig-param"><span class="n">y</span><span class="o">=</span><span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/sklearn.html#OptunaSearchCV.score"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.OptunaSearchCV.score" title="永久链接至目标">¶</a></dt>
<dd><p>返回给定数据的 score。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>X</strong> -- Data.</p></li>
<li><p><strong>y</strong> -- 目标变量。</p></li>
</ul>
</dd>
<dt class="field-even">返回</dt>
<dd class="field-even"><p>Scaler score.</p>
</dd>
<dt class="field-odd">返回类型</dt>
<dd class="field-odd"><p>score</p>
</dd>
</dl>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.score_samples">
<em class="property">property </em><code class="sig-name descname">score_samples</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.score_samples" title="永久链接至目标">¶</a></dt>
<dd><p>调用最佳 estimator 的 <code class="docutils literal notranslate"><span class="pre">score_samples</span></code> 。</p>
<p>它只有在对应的 estimator支持  <code class="docutils literal notranslate"><span class="pre">score_samples</span></code> 和 <code class="docutils literal notranslate"><span class="pre">refit</span></code> 设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的情况下可用。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.set_user_attr">
<em class="property">property </em><code class="sig-name descname">set_user_attr</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.set_user_attr" title="永久链接至目标">¶</a></dt>
<dd><p>调用 <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 的 <code class="docutils literal notranslate"><span class="pre">set_user_attr</span></code> 。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.transform">
<em class="property">property </em><code class="sig-name descname">transform</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.transform" title="永久链接至目标">¶</a></dt>
<dd><p>调用最佳 estimator 的 <code class="docutils literal notranslate"><span class="pre">transform</span></code> 。</p>
<p>它只有在对应的 estimator支持  <code class="docutils literal notranslate"><span class="pre">transform</span></code> 和 <code class="docutils literal notranslate"><span class="pre">refit</span></code> 设置成 <a class="reference external" href="https://docs.python.org/3/library/constants.html#True" title="(在 Python v3.8)"><code class="xref py py-obj docutils literal notranslate"><span class="pre">True</span></code></a> 的情况下可用。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.trials_">
<em class="property">property </em><code class="sig-name descname">trials_</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.trials_" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 中的所有 trial。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.trials_dataframe">
<em class="property">property </em><code class="sig-name descname">trials_dataframe</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.trials_dataframe" title="永久链接至目标">¶</a></dt>
<dd><p>调用 <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 的 <code class="docutils literal notranslate"><span class="pre">trials_dataframe</span></code> 。</p>
</dd></dl>

<dl class="py method">
<dt id="optuna.integration.OptunaSearchCV.user_attrs_">
<em class="property">property </em><code class="sig-name descname">user_attrs_</code><a class="headerlink" href="#optuna.integration.OptunaSearchCV.user_attrs_" title="永久链接至目标">¶</a></dt>
<dd><p><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 中的用户属性。</p>
</dd></dl>

</dd></dl>

<dl class="py class">
<dt id="optuna.integration.AllenNLPExecutor">
<em class="property">class </em><code class="sig-prename descclassname">optuna.integration.</code><code class="sig-name descname">AllenNLPExecutor</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">trial</span><span class="p">:</span> <span class="n">optuna.trial._trial.Trial</span></em>, <em class="sig-param"><span class="n">config_file</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a></span></em>, <em class="sig-param"><span class="n">serialization_dir</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a></span></em>, <em class="sig-param"><span class="n">metrics</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a></span> <span class="o">=</span> <span class="default_value">'best_validation_accuracy'</span></em>, <em class="sig-param"><span class="o">*</span></em>, <em class="sig-param"><span class="n">include_package</span><span class="p">:</span> <span class="n">Union[str, List[str], None]</span> <span class="o">=</span> <span class="default_value">None</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/optuna/integration/allennlp.html#AllenNLPExecutor"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.AllenNLPExecutor" title="永久链接至目标">¶</a></dt>
<dd><p>为了让 Jsonnet 配置文件在 Optuna 中可用的 AllenNLP 扩展。</p>
<p>这是个试验性的特性，因为 AllenNLP 的下一个主要版本将发行。而该接口可能在没有提前告知更新的情况下改变。</p>
<p>参见 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/allennlp/allennlp_jsonnet.py">objective function</a> 和 <a class="reference external" href="https://github.com/optuna/optuna/blob/master/examples/allennlp/classifier.jsonnet">config file</a> 的例子。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>trial</strong> -- 对应于目标函数本次求值的 <a class="reference internal" href="trial.html#optuna.trial.Trial" title="optuna.trial.Trial"><code class="xref py py-class docutils literal notranslate"><span class="pre">Trial</span></code></a>。</p></li>
<li><p><strong>config_file</strong> -- AllenNLP 的配置文件。其中超参数应当在外面套一层 <code class="docutils literal notranslate"><span class="pre">std.extVar</span></code> 。参见 <a class="reference external" href="https://github.com/allenai/allentune/blob/master/examples/classifier.jsonnet">the config example</a>.</p></li>
<li><p><strong>serialization_dir</strong> -- 用于存储模型权重和日志的路径。</p></li>
<li><p><strong>metrics</strong> -- 用于评估 <code class="docutils literal notranslate"><span class="pre">objective</span></code> 结果的度量。</p></li>
<li><p><strong>include_package</strong> -- 要包含的额外包，更多信息参见 <a class="reference external" href="https://docs.allennlp.org/master/api/commands/train/">AllenNLP documentation</a>.</p></li>
</ul>
</dd>
</dl>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>在 v1.4.0 中作为试验性特性引入，在未来版本中，该接口可能在没有预先告知的情况下被改变。参考 <a class="reference external" href="https://github.com/optuna/optuna/releases/tag/v1.4.0">https://github.com/optuna/optuna/releases/tag/v1.4.0</a>.</p>
</div>
<dl class="py method">
<dt id="optuna.integration.AllenNLPExecutor.run">
<code class="sig-name descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span> &#x2192; <a class="reference external" href="https://docs.python.org/3/library/functions.html#float" title="(在 Python v3.8)">float</a><a class="reference internal" href="../_modules/optuna/integration/allennlp.html#AllenNLPExecutor.run"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.AllenNLPExecutor.run" title="永久链接至目标">¶</a></dt>
<dd><p>用 AllenNLP 来训练一个模型。</p>
</dd></dl>

</dd></dl>

<dl class="py function">
<dt id="optuna.integration.allennlp.dump_best_config">
<code class="sig-prename descclassname">optuna.integration.allennlp.</code><code class="sig-name descname">dump_best_config</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">input_config_file</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a></span></em>, <em class="sig-param"><span class="n">output_config_file</span><span class="p">:</span> <span class="n"><a class="reference external" href="https://docs.python.org/3/library/stdtypes.html#str" title="(在 Python v3.8)">str</a></span></em>, <em class="sig-param"><span class="n">study</span><span class="p">:</span> <span class="n"><a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study">optuna.study.Study</a></span></em><span class="sig-paren">)</span> &#x2192; <a class="reference external" href="https://docs.python.org/3/library/constants.html#None" title="(在 Python v3.8)">None</a><a class="reference internal" href="../_modules/optuna/integration/allennlp.html#dump_best_config"><span class="viewcode-link">[源代码]</span></a><a class="headerlink" href="#optuna.integration.allennlp.dump_best_config" title="永久链接至目标">¶</a></dt>
<dd><p>在 study 中的最佳参数更新后存储 JSON 配置文件。</p>
<dl class="field-list simple">
<dt class="field-odd">参数</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>input_config_file</strong> -- 被 <a class="reference internal" href="#optuna.integration.AllenNLPExecutor" title="optuna.integration.AllenNLPExecutor"><code class="xref py py-class docutils literal notranslate"><span class="pre">AllenNLPExecutor</span></code></a> 使用的输入 Jsonnet 配置文件。</p></li>
<li><p><strong>output_config_file</strong> -- 输出 JSON 配置文件。</p></li>
<li><p><strong>study</strong> -- <a class="reference internal" href="study.html#optuna.study.Study" title="optuna.study.Study"><code class="xref py py-class docutils literal notranslate"><span class="pre">Study</span></code></a> 实例。注意它必须在 <a class="reference internal" href="study.html#optuna.study.Study.optimize" title="optuna.study.Study.optimize"><code class="xref py py-func docutils literal notranslate"><span class="pre">optimize()</span></code></a> 已经被调用的情况下使用。</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="logging.html" class="btn btn-neutral float-right" title="Logging" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="importance.html" class="btn btn-neutral float-left" title="Hyperparameter Importance" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, Optuna Contributors.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
    <a href="../privacy.html">Privacy Policy</a>.
     


</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
    <!-- Theme Analytics -->
    <script>
    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
    })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-55135190-8', 'auto');
    ga('send', 'pageview');
    </script>

    
   

</body>
</html>